import 'package:enterprise_v6_app/app/core/core.dart';
import 'package:enterprise_v6_app/app/core/utils/module_permissions_util.dart';
import 'package:enterprise_v6_app/app/core/utils/user_manager.dart';
import 'package:enterprise_v6_app/app/data/entities/application/securtity_base_drawer.dart';
import 'package:enterprise_v6_app/app/modules/task/task_all/education/education_view.dart';
import 'package:enterprise_v6_app/app/modules/task/task_all/hazard_investigation/hazard_investigation_view.dart';
import 'package:enterprise_v6_app/app/modules/task/task_all/inspec_task_page/inspec_task_view.dart';
import 'package:enterprise_v6_app/app/modules/task/task_all/process_execution/process_execution_view.dart';
import 'package:enterprise_v6_app/app/modules/task/task_all/responsibility/security_responsibility_view.dart';
import 'package:enterprise_v6_app/app/modules/task/task_all/risk_control/risk_control_view.dart';
import 'package:enterprise_v6_app/app/modules/task/task_all/security_all_fundamentals_page/security_all_fundamentals_page_view.dart';
import 'package:enterprise_v6_app/app/modules/task/task_all/task_closure/closure_view.dart';
import 'package:enterprise_v6_app/app/modules/task/task_all/task_emergency/task_emergency_view.dart';

class TaskAllController extends GetxController {
  /// 筛选右侧栏控制Key
  final popRightScaffoldKey = GlobalKey<ScaffoldState>();

  /// 展开收起控制key
  final scaffoldKey = GlobalKey<ScaffoldState>();

  /// 选中的页面
  int selectIndex = 0;

  /// 右侧筛选样式
  Widget? filterWidget;

  // 标题列表
  final titleList = <SecurityBaseEntity>[];

  @override
  void onReady() {
    super.onReady();
    // 如果没有登录,则不执行逻辑,防止请求401
    if (!UserManager.isLoggedIn) {
      return;
    }
    _initTitleList();
  }

  Future<void> _initTitleList() async {
    titleList.clear();
    titleList.addAll([
      SecurityBaseEntity(
          title: '安全基础',
          icon: AppImages.icon_sask_security_fundamentals,
          expandTitle: '安全基础',
          currentPageTitle: 0,
          // pages: [SecurityFundamentalsPage()],
          pages: [SecurityAllFundamentalsPagePage()],
          path: '/basicInformation'),
      SecurityBaseEntity(
        title: '风险管控',
        icon: AppImages.icon_sask_risk_control,
        expandTitle: '风险管控',
        currentPageTitle: 0,
        pages: [RiskControlPage()],
        path: '/riskControl',
      ),
      SecurityBaseEntity(
          title: '隐患排查',
          icon: AppImages.icon_sask_hazard_investigation,
          expandTitle: '隐患排查',
          currentPageTitle: 0,
          pages: [HazardInvestigationPage()],
          path: '/hiddenDiseaseSearch'),
      SecurityBaseEntity(
          title: '智能巡检',
          icon: AppImages.icon_sask_intelligent_inspection,
          expandTitle: '智能巡检',
          currentPageTitle: 0,
          pages: [InspecTaskPage()],
          path: '/intelligentInspection'),
      SecurityBaseEntity(
          title: '包保责任',
          icon: AppImages.icon_personnel_management,
          expandTitle: '包保责任',
          currentPageTitle: 0,
          pages: [SecurityResponsibilityPage()],
          path: '/securityResponsibility'),
      SecurityBaseEntity(
        title: '教育培训',
        icon: AppImages.icon_train_teacher,
        expandTitle: '教育培训',
        currentPageTitle: 0,
        pages: [EducationPage()],
        path: '/educationTraining',
      ),
      SecurityBaseEntity(
        title: '敏捷应急',
        icon: AppImages.icon_production_process,
        expandTitle: '敏捷应急',
        currentPageTitle: 0,
        pages: [TaskEmergencyPage()],
        path: '/emergency',
      ),
      SecurityBaseEntity(
        title: '封闭化',
        icon: AppImages.icon_closure,
        expandTitle: '封闭化',
        currentPageTitle: 0,
        pages: [TaskClosurePage()],
        path: '/closure',
      ),
      SecurityBaseEntity(
        title: '功能中心',
        icon: AppImages.icon_file,
        expandTitle: '功能中心',
        currentPageTitle: 0,
        pages: [ProcessExecutionPage()],
        path: '/functionCenter',
      ),
      // SecurityBaseEntity(
      //   title: '重大危险',
      //   icon: AppImages.icon_sask_major_hazards,
      //   expandTitle: '重大危险',
      //   currentPageTitle: 0,
      //   pages: [Container()],
      // ),
    ]);
    await ModulePermissionsUtil.removeTaskRoleMenu(titleList: titleList);
    update();
  }

  /// 点击左侧菜单
  /// [index] 索引
  void selectLeftMenu(int index) {
    selectIndex = index;
    update();
  }

  /// title选择切换
  /// [titleIndex] 标题索引
  /// [index] 页面索引
  void selectTitle(int titleIndex, int index) {
    titleList[titleIndex].currentPageTitle = index;
    update();
  }

  /// 点击展开菜单
  /// [index] 索引
  void selectExpandMenu(int index) {
    selectIndex = index;
    Get.back();
    update();
  }
}
